package cn.yangyumanage.util;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import android.util.Base64;


public class Aes {
    //秘钥
    private static final String KEY = "1234567890123456";
    //加密模式
    private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding";

    //加密
//    public static String encrypt(String content) throws Exception {
//        Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
//        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY.getBytes(), "AES"));
//        byte[] b = cipher.doFinal(content.getBytes(StandardCharsets.UTF_8));
//        return Base64.getEncoder().encodeToString(b);
//    }

    //解密
    public static String decrypt(String encryptStr) throws Exception {
        Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY.getBytes(), "AES"));
        byte[] encryptBytes = Base64.decode(encryptStr,Base64.DEFAULT);
        byte[] decryptBytes = cipher.doFinal(encryptBytes);
        return new String(decryptBytes);
    }
}


